<template>
  <div class="base-container">
    <t-form ref="form" :data="queryParams" label-width="64"
            @submit="()=>{this.pagination.current=1;this.getMyList()}"
            @reset="()=>{this.pagination.current=1;this.getMyList()}">
      <t-row style="border-bottom: 1px solid #E5E6EB;margin-bottom: 10px">
        <t-col :span="11" class="query-form-inline">
          <t-form-item label="系统名称" name="systemName">
            <t-input
              v-model="queryParams.systemName"
              clearable
              placeholder="请输入系统名称"
              style="width: 240px"
            />
          </t-form-item>
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button theme="primary" type="submit"> 查询</t-button>
          <t-button theme="default" variant="outline" type="reset">重置</t-button>
        </t-col>
      </t-row>
    </t-form>
    <!-- 系统列表内容 -->
    <t-table
    rowKey="id"
    :data="data"
    :columns="columns"
    hover
    :pagination="pagination"
    :loading="dataLoading"
  >
    <template #linker="{row}">
      <div v-for="(item,index) in row.linker.filter(val => val.memberType === '1')" :key="index">{{ item.name }}</div>
    </template>
    <template #dutyPerson="{row}">
      <div v-for="(item,index) in row.dutyPerson.filter(val => val.memberType === '1')" :key="index">{{ item.name }}</div>
    </template>
    <template #liaisonPerson="{row}">
      <div v-for="(item,index) in row.liaisonPerson.filter(val => val.memberType === '1')" :key="index">{{ item.name }}</div>
    </template>
    <template #approveStatus="{row}">
      {{ row.approveStatus | filterByDict(dict.type.approve_status) }}
    </template>
    <template #op="{ row }">
      <t-button @click="dialog.header='修改我的系统评价'; dialog.objId = row.id; dialog.open = true;" size="small"
                variant="text" class="t-button-link">
        <t-icon name="edit-1" slot="icon"/>
        修改
      </t-button>
      <t-button theme="danger" @click="delObj(row)" size="small" variant="text" class="t-button-link">
        <t-icon name="delete" slot="icon"/>
        删除
      </t-button>
    </template>
  </t-table>
  </div>
</template>

<script>

export default {
  dicts: ["system_status","approve_status"],
  data(){
    return {
      dialog:{
        header: '',
        objId: null,
        open: false
      },
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        systemName: '',
        systemStatus: '',
        startScore: '',
        endScore:'',
        approveStatus:'',
      },
      data: [],
      dataLoading: false,
      columns: [
        {
          colKey: "name",
          title: "系统名称",
          align: "center",
        },
        {
          colKey: "linker",
          title: "应用联系人",
          align: "center",
        },
        {
          colKey: "dutyPerson",
          title: "建设责任人",
          align: "center",
        },
        {
          colKey: "liaisonPerson",
          title: "建设联络员",
          align: "center",
        },
        {
          colKey: "liaisonDate",
          title: "建设年月",
          align: "center",

        },
        {
          colKey: "completeDate",
          title: "完成年月",
          align: "center",
        },
        {
          colKey: "score",
          title: "应用评价分数",
          align: "center",
        },
        {
          colKey: "approveStatus",
          title: "评价状态",
          align: "center",
        },
        {
          colKey: "op",
          title: "操作",
          align: "center",
        },
      ],
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showPageSize: true,
        pageSizeOptions: [10, 20, 30],
        showFirstAndLastPageBtn: false,
        onChange: (pageInfo) => {
          Object.assign(this.pagination, pageInfo)
          this.queryParams.pageNum = pageInfo.current || 1;
          this.queryParams.pageSize = pageInfo.pageSize;
          this.getMyList()
        },
      },
    }
  },
  created(){
    this.getMyList();
  },
  methods:{
    getMyList(){
      this.dataLoading = true;
      this.$api.yxjk.review.myScoreList(this.queryParams).then(response => {
        this.pagination.total = response.total;
        this.data = response.rows;
        this.dataLoading = false;
      }).catch((e) => {
        this.dataLoading = false;
        this.$message.error(e.toString());
      });
    },
    delObj(row){
      const confirmDia = this.$dialog.confirm({
        header: "系统提示",
        body: `是否确认删除系统名称为"${row.name}"的数据项？`,
        theme: "warning",
        onConfirm: ({ e }) => {
          this.$api.yxjk.system.del(row.id).then(
            (res) => {
              this.getList();
              this.$message.success("删除成功");
              // 请求成功后，销毁弹框
              confirmDia.destroy();
            }
          ).catch((e) => {
            this.$message.error(e.toString());
          });
        }
      });
    },
  }
}
</script>
